/** @file GOTHgpio.h This file contains the API for GPIO of the GOTH Kick-ass Etherboard.
 * Currently, the following hardware is supported:
 *	- the 2 push buttons
 *  - the 2 dip switches
 *	- the 8 leds
 *
 * @author Geoffrey Ottoy - Tom Hamelinckx
 * @date 01/07/2011 (last modified)
 *
 * <pre>
 * MODIFICATION HISTORY:
 *
 * Who  Date     Changes
 * ---- -------- ---------------------------------------------------------
 * GO   30/06/11 Created this file based on a previous file by TH.
 * GO   01/07/11 Added toggle leds and clear leds functionality.
 * </pre>
 * 
 */

#ifndef __GOTH_GPIO_H__
#define __GOTH_GPIO_H__

#include <p24fj256gb110.h>
#include "GOTHglobal.h"

/* All the functionality for the push buttons */
#define BTN_1 0XF0F0
#define BTN_2 0X0F0F
#define BOTH_BTNS 0XFFFF
#define RISING  0
#define FALLING 1

/** Initialize the dip switches for operation
 * @param	button_nr	Determines which button is initialized. Choose
 *						between BTN_1, BTN_2 and BOTH_BTNS.
 * @return	nothing
 */
void GPIO_InitBtns(unsigned int button_nr);

/** Enables the buttons interrupt (INT1 resp. INT2). You can use GPIO_Btn#Pressed()
 * to check wether a button was pressed or not.
 * @param	button_nr	Determines which button interrupt is turned on. Choose
 *						between BTN_1, BTN_2 and BOTH_BTNS.
 * @return	nothing
 */
void GPIO_EnableBtns(unsigned int button_nr);

/** Disables the buttons interrupt (INT1 resp. INT2). 
 * @param	button_nr	Determines which button interrupt is turned off. Choose
 *						between BTN_1, BTN_2 and BOTH_BTNS.
 * @return	nothing
 */
void GPIO_DisableBtns(unsigned int button_nr);

/** Check if BTN_1 was pressed.
 *
 * @return	The number of button presses.
 */
int GPIO_Btn1Pressed();

/** Check if BTN_2 was pressed.
 *
 * @return	The number of button presses.
 */
int GPIO_Btn2Pressed();

/* All the functionality for the dip switches */

/** Initialize the dip switches for operation
 *
 * @return	nothing
 */
void GPIO_InitDips();

/** Get the current value of the dip switches
 *
 * @return	The current value of the dip switches (1 = on, 0 = off)
 */
unsigned int GPIO_GetDipsValue();

/* All the functionality for the leds */

#define RED_LED_0		0x80
#define ORANGE_LED_2	0x40
#define ORANGE_LED_1	0x20
#define ORANGE_LED_0	0x10
#define GREEN_LED_3		0x08
#define GREEN_LED_2		0x04
#define GREEN_LED_1		0x02
#define GREEN_LED_0		0x01
#define ALL_LEDS		0xFF

/** Initialize the leds for operation
 *
 * @return	nothing
 */
void GPIO_InitLeds();

/** Turn a led on or set the value of all leds
 *
 * @param	identifier	This is the new value for the leds (1 = on, 0 = off). Alternatively one can
 *						do something like this:
 *						GPIO_SetLeds(RED_LED_0 | GREEN_LED_2 | GREEN_LED_1);
 * @return	nothing
 */
void GPIO_SetLeds(unsigned char identifier);

/** Toggle the leds
 *
 * @param	identifier	This determines which leds will be toggled
 * @return	nothing
 */
void GPIO_ToggleLeds(unsigned char identifier);

/** Toggle the leds
 *
 * @param	identifier	This determines which leds will be cleared
 * @return	nothing
 */
void GPIO_ClearLeds(unsigned char identifier);

#endif //__GOTH_GPIO_H__
